package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealMapper {

    /**
     * 根据分类id查询套餐数量
     * @param id
     * @return
     */
    @Select("select count(0) from setmeal where category_id = #{id}")
    Integer countByCategoryId(Long id);

    @Select("select count(0) from setmeal where dish_id = #{id}")
    Integer countByDishId(Long id);

    /**
     * 新增套餐
     * @param setmeal
     */
    @AutoFill(OperationType.INSERT)
    void addSetmeal(Setmeal setmeal);

    /**
     * 分页获取套餐信息
     * @param setmealPageQueryDTO
     * @return
     */
    List<SetmealVO> queryPage(SetmealPageQueryDTO setmealPageQueryDTO);

    /**
     * 更新套餐信息
     * @param setmeal
     */
    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);

    /**
     * 根据id查询套餐信息
     * @param id
     * @return
     */
    @Select("select * from setmeal where id = #{id}")
    Setmeal getbyId(Long id);

    /**
     * 根据id查询套餐状态
     * @param id
     * @return
     */
    @Select("select status from setmeal where id = #{id}")
    int getStatusById(Long id);

    /**
     * 批量删除套餐
     * @param ids
     */
    void deleteBatch(List<Long> ids);

    /**
     * 根据分类id查询套餐列表
     * @param categoryId
     * @return
     */
    @Select("select * from setmeal where category_id = #{categoryId}")
    List<Setmeal> getSetmealsByCategoryId(Long categoryId);

    /**
     * 根据套餐id查询包含菜品信息
     * @param id
     * @return
     */
    List<DishItemVO> getDishBySetmealId(Long id);


    /**
     * 统计启售/停售套餐数量
     * @param status
     * @return
     */
    @Select("select count(id) from setmeal where status = #{status} ")
    Integer overviewSetmeals(Integer status);
}
